<?php
/**
 * Created by PhpStorm.
 * User: FDG296
 * Date: 2017/7/10
 * Time: 15:33
 */
namespace common\models;

use Yii;
use yii\db\ActiveRecord;

class GoodsRelation extends ActiveRecord{
    public static function tableName(){
        return '{{%goods_relation}}';
    }

    //获取进口家具搭配套餐主商品
    public function getMainGoodsId($id){
        $where = ['use_flg'=>1,'relation_key'=>'buy_set_'.$id];
        //获取主商品id
        $result = $this::find()->where($where)->limit(3)->orderBy('sort asc')->select('main_goods_id')->asArray()->all();
        if(!empty($result)){
            $main_goods_id = array_column($result,'main_goods_id');
        }else{
            $main_goods_id = '';
        }
        return $main_goods_id;
    }

    //获取商品搭配
    public function getGoodsGroupList($id){
        $where = ['use_flg'=>1,'relation_key'=>'goods_'.$id];
        //获取主商品id
        $result = $this::find()->where($where)->limit(4)->orderBy('sort asc')->select('main_goods_id')->asArray()->all();
        if(!empty($result)){
            $main_goods_id = array_column($result,'main_goods_id');
        }else{
            $main_goods_id = '';
        }
        return $main_goods_id;
    }
}